Include Nur.DateFormat

/// Creator:      fengliang
/// CreatDate:    2021-03-12
/// Description:  巡视记录汇总表
/// 注:此表作为查询、统计用途,不给前台页面单独提供增删改功能。
Class Nur.MNISV3.SumTourRec Extends %Persistent
{

/// 巡视日期
Property DHCNurTourDate As %Library.Date(FORMAT = 1) [ InitialExpression = {+$p($h,",",1)}, Required, SqlColumnNumber = 2 ];

/// 巡视时间
Property DHCNurTourTime As %Library.Time [ InitialExpression = {+$p($h,",",2)}, Required, SqlColumnNumber = 3 ];

/// 巡视病人就诊号
Property DHCNurTourAdmDR As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 4 ];

/// 巡视患者所在病区
Property DHCNurTourCtlocDR As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 5 ];

/// 巡视人
Property DHCNurTourUser As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 6 ];

/// 巡视类型
Property DHCNurTourType As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 7 ];

/// 巡视明细表指向
Property DHCNurTourDetailDR As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 8 ];

/// 作废人
Property DHCNurTourCancelUser As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 9 ];

/// 作废日期
Property DHCNurTourCancelDate As %Library.Date(FORMAT = 1) [ SqlColumnNumber = 10 ];

/// 作废时间
Property DHCNurTourCancelTime As %Library.Time [ SqlColumnNumber = 11 ];

Index TourDateAdm On (DHCNurTourDate, DHCNurTourCtlocDR, DHCNurTourAdmDR);

Index TourDate On DHCNurTourDate;

Index TourAdmUser On (DHCNurTourDate, DHCNurTourCtlocDR, DHCNurTourAdmDR, DHCNurTourUser);

Index TourUser On (DHCNurTourDate, DHCNurTourCtlocDR, DHCNurTourUser);

Index TourTypeSub On (DHCNurTourType, DHCNurTourDetailDR);

Index TourDateAdmTime On (DHCNurTourDate, DHCNurTourCtlocDR, DHCNurTourAdmDR, DHCNurTourTime);

/// Creator:      lmm
/// CreatDate:    2019-04-19
/// Description:  汇总表保存
/// Input：       parr:数据串(key|value^key|value),detailId:明细表ID,userId:用户ID
/// other:        w ##class(Nur.MNISV3.SumTourRec).Save()
ClassMethod Save(parr As %String, detailId As %String, tourType As %String, userId As %String) As %String
{
    q:detailId="" "err:"_"明细表ID不能为空"
    q:tourType="" "err:"_"巡视类型不能为空"
    s tmp=""
    s a=##class(web.DHCMGNurComm).setmoudtmp(parr,.tmp)
    
    //通过明细表ID和巡视类型取汇总表ID
    s id=""
    s tmpTourType=$ZConvert(tourType,"U")
    i $d(^Nur.MNISV3.SumTourRecI("TourTypeSub"," "_tmpTourType," "_detailId))  d
    .s id=$o(^Nur.MNISV3.SumTourRecI("TourTypeSub"," "_tmpTourType," "_detailId,""))
    
    i (id=""){
        s rec=##class(Nur.MNISV3.SumTourRec).%New()
    }else{
        s rec=##class(Nur.MNISV3.SumTourRec).%OpenId(id)
    }
    
    i '$d(tmp("DHCNurTourDate"))  d
    .s tmp("DHCNurTourDate")=+$h
    e  d
    .i tmp("DHCNurTourDate")["-" s tmp("DHCNurTourDate")=$zdh(tmp("DHCNurTourDate"),3)
    .i tmp("DHCNurTourDate")["/" s tmp("DHCNurTourDate")=$zdh(tmp("DHCNurTourDate"),1)  
    i '$d(tmp("DHCNurTourTime"))  d
    .s tmp("DHCNurTourTime")=$p($h,",",2)
    e  d
    .i tmp("DHCNurTourTime")[":" s tmp("DHCNurTourTime")=$zth(tmp("DHCNurTourTime"))
    i $d(tmp("DHCNurTourDate")) s rec.DHCNurTourDate=tmp("DHCNurTourDate")
    i $d(tmp("DHCNurTourTime")) s rec.DHCNurTourTime=tmp("DHCNurTourTime")
    i $d(tmp("DHCNurTourAdmDR")) s rec.DHCNurTourAdmDR=tmp("DHCNurTourAdmDR")
    i $d(tmp("DHCNurTourCtlocDR")) s rec.DHCNurTourCtlocDR=tmp("DHCNurTourCtlocDR")
    s rec.DHCNurTourUser=userId
    s rec.DHCNurTourType=tourType
    s rec.DHCNurTourDetailDR=detailId
    s sc=rec.%Save()
    q:$$$ISERR(sc) "err:"_$SYSTEM.Status.GetErrorText(sc)
    q rec.%Id()
}

/// Creator:      lmm
/// CreatDate:    2019-04-19
/// Description:  汇总巡视删除
/// Input：       detailId:明细表ID,tourType:巡视类型,userId:用户ID
/// other:        w ##class(Nur.MNISV3.SumTourRec).Delete()
ClassMethod Delete(detailId As %String, tourType As %String, userId As %String) As %String
{
    q:detailId="" "err:"_"明细表ID不能为空"
    q:tourType="" "err:"_"巡视类型不能为空"
    //通过明细表ID和巡视类型取汇总表ID
    s id=""
    s tourType=$zconvert(tourType,"U")
    i $d(^Nur.MNISV3.SumTourRecI("TourTypeSub"," "_tourType," "_detailId))  d
    .s id=$o(^Nur.MNISV3.SumTourRecI("TourTypeSub"," "_tourType," "_detailId,"")) 
    q:id="" "err:"_"汇总表不能找到对应的巡视记录"
    s rec=##class(Nur.MNISV3.SumTourRec).%OpenId(id)
    s rec.DHCNurTourCancelUser=userId
    s rec.DHCNurTourCancelDate=+$h
    s rec.DHCNurTourCancelTime=$p(+$h,",",2)
    s sc=rec.%Save()
    q:$$$ISERR(sc) "err:"_$SYSTEM.Status.GetErrorText(sc)
    q 0
}

Storage Default
{
<Data name="SumTourRecDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>DHCNurTourDate</Value>
</Value>
<Value name="3">
<Value>DHCNurTourTime</Value>
</Value>
<Value name="4">
<Value>DHCNurTourAdmDR</Value>
</Value>
<Value name="5">
<Value>DHCNurTourCtlocDR</Value>
</Value>
<Value name="6">
<Value>DHCNurTourUser</Value>
</Value>
<Value name="7">
<Value>DHCNurTourType</Value>
</Value>
<Value name="8">
<Value>DHCNurTourDetailDR</Value>
</Value>
<Value name="9">
<Value>DHCNurTourCancelUser</Value>
</Value>
<Value name="10">
<Value>DHCNurTourCancelDate</Value>
</Value>
<Value name="11">
<Value>DHCNurTourCancelTime</Value>
</Value>
</Data>
<DataLocation>^Nur.MNISV3.SumTourRecD</DataLocation>
<DefaultData>SumTourRecDefaultData</DefaultData>
<ExtentSize>4</ExtentSize>
<IdLocation>^Nur.MNISV3.SumTourRecD</IdLocation>
<IndexLocation>^Nur.MNISV3.SumTourRecI</IndexLocation>
<Property name="%%CLASSNAME">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="%%ID">
<AverageFieldSize>3</AverageFieldSize>
<Selectivity>1</Selectivity>
</Property>
<Property name="DHCNurTourAdmDR">
<AverageFieldSize>6</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourCancelDate">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourCancelTime">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourCancelUser">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourCtlocDR">
<AverageFieldSize>3</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourDate">
<AverageFieldSize>5</AverageFieldSize>
<Selectivity>50.0000%</Selectivity>
</Property>
<Property name="DHCNurTourDetailDR">
<AverageFieldSize>3</AverageFieldSize>
<Selectivity>25.0000%</Selectivity>
</Property>
<Property name="DHCNurTourTime">
<AverageFieldSize>4</AverageFieldSize>
<Selectivity>25.0000%</Selectivity>
</Property>
<Property name="DHCNurTourType">
<AverageFieldSize>7</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourUser">
<AverageFieldSize>7</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<SQLMap name="IDKEY">
<BlockCount>-4</BlockCount>
</SQLMap>
<SQLMap name="TourAdmUser">
<BlockCount>-4</BlockCount>
</SQLMap>
<SQLMap name="TourDate">
<BlockCount>-4</BlockCount>
</SQLMap>
<SQLMap name="TourDateAdm">
<BlockCount>-4</BlockCount>
</SQLMap>
<SQLMap name="TourDateAdmTime">
<BlockCount>-4</BlockCount>
</SQLMap>
<SQLMap name="TourTypeSub">
<BlockCount>-4</BlockCount>
</SQLMap>
<SQLMap name="TourUser">
<BlockCount>-4</BlockCount>
</SQLMap>
<StreamLocation>^Nur.MNISV3.SumTourRecS</StreamLocation>
<Type>%Storage.Persistent</Type>
}

}
